package com.daocao.jy.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.daocao.jy.R;
import com.daocao.jy.api.model.CouponListModel;
import com.daocao.jy.util.DateTime;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class MyCouponAdapter extends ItemAdapter<CouponListModel.DatasBean, MyCouponAdapter.DefaultHolder> {

    private int type;

    public MyCouponAdapter(Context context, int type) {
        super(context);
        this.type = type;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_my_coupon, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        CouponListModel.DatasBean item = getItem(position);
        switch (type) {
            case 0:
                holder.layoutTotal.setBackgroundResource(R.mipmap.img_youhui_use_bg);

                break;
            case 1:
                holder.layoutTotal.setBackgroundResource(R.mipmap.img_youhui_used_bg);
                holder.imgStatus.setImageResource(R.mipmap.img_youhui_status_used);
                holder.txtTitle.setTextColor(0xff999999);
                holder.txtContent.setTextColor(0xff999999);
                break;
            case 2:
                holder.layoutTotal.setBackgroundResource(R.mipmap.img_youhui_used_bg);
                holder.imgStatus.setImageResource(R.mipmap.img_youhui_status_timeout);
                holder.txtTitle.setTextColor(0xff999999);
                holder.txtContent.setTextColor(0xff999999);
                break;
        }
        holder.txtTitle.setText(item.title);
        holder.txtContent.setText(item.limit_desc);
        holder.txtUseDesc.setText(item.use_desc);
        holder.txtMoney.setText(item.par + "\n立即使用");
//        有效期 2018.04.08 00:00:00 - 2018.07.04 23:59:59
        holder.txtTime.setText("有效时间" + DateTime.toDateTime(item.start_date * 1000) + "-" + DateTime.toDateTime(item.end_date * 1000));
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_money)
        TextView txtMoney;
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.txt_content)
        TextView txtContent;
        @BindView(R.id.txt_time)
        TextView txtTime;
        @BindView(R.id.img_status)
        ImageView imgStatus;
        @BindView(R.id.layout_total)
        LinearLayout layoutTotal;
        @BindView(R.id.txt_use_desc)
        TextView txtUseDesc;


        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
